﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SH.Common.CommonReturn;
using SH.Room.Application.IServices.IRoomPrice;
using SH.Room.Domain.RoomClass;

namespace SH.Room.Read.API.Controllers
{
    /// <summary>
    /// 房价管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomPriceController : ControllerBase
    {
        private readonly IRoomPriceServices _roomPriceServices;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="roomPriceServices"></param>
        public RoomPriceController(IRoomPriceServices roomPriceServices)
        {
            _roomPriceServices = roomPriceServices;
        }

        /// <summary>
        /// 房价添加
        /// </summary>
        /// <param name="roomPriceAddDto">房价DTO</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public async Task<IActionResult> RoomPriceAdd(RoomPriceAddDto roomPriceAddDto)
        {
            var res=await _roomPriceServices.RoomPriceAdd(roomPriceAddDto);
            return Ok(res);
        }

        /// <summary>
        /// 房价显示、查询
        /// </summary>
        /// <param name="rtid">房型ID</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult GetRoomPriceList(int rtid)
        {
           var result=_roomPriceServices.GetRoomPriceList(rtid);
            return Ok(result);
        }

        /// <summary>
        /// 房价删除
        /// </summary>
        /// <param name="rpid">房价ID</param>
        /// <returns>受影响行数</returns>
        [HttpDelete]
        public IActionResult DelRoomprice(int rpid)
        {
            var result = _roomPriceServices.DelRoomprice(rpid);
            return Ok(result);
        }

        /// <summary>
        /// 房价反填
        /// </summary>
        /// <param name="rpid">房价ID</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult FindRoomPrice(int rpid)
        {
            ApiResult<RoomPrice> apiResult=new ApiResult<RoomPrice>();
            var item = _roomPriceServices.GetModelByCondition(x => x.RpId == rpid);
            apiResult.Success(item);
            return Ok(apiResult);
        }

        /// <summary>
        /// 房价修改
        /// </summary>
        /// <param name="roomPriceUpdDto">房价修改DTO</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public IActionResult UpdRoomPrice(RoomPriceUpdDto roomPriceUpdDto)
        {
            var result=_roomPriceServices.UpdRoomPrice(roomPriceUpdDto);
            return Ok(result);
        }

        /// <summary>
        /// 修改房价状态
        /// </summary>
        /// <param name="rpid">房价ID</param>
        /// <param name="state">状态</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public IActionResult GetRoomPriceState(int rpid, bool state)
        {
            var res=_roomPriceServices.GetRoomPriceState(rpid, state);
            return Ok(res);
        }
    }
}
